/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package beans;

import bc.ColorPrendaFacadeLocal;
import be.ColorPrenda;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import javax.ejb.EJB;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import javax.faces.model.SelectItem;

/**
 *
 **Copyright  2011 Yury Daniel Zavaleta De la Cruz
 * Licensed under the Apache License,
 * Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * http://www.apache.org/licenses/LICENSE-2.0
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and  limitations under the License.
 */
@ManagedBean
@SessionScoped
public class ManagedBeanColorPrenda implements Serializable{
    @EJB
    private ColorPrendaFacadeLocal colorPrendaFacade;
private List<ColorPrenda> lista;
 private List<SelectItem> colorprendasItems = new LinkedList<SelectItem>();
private HashMap<Integer, ColorPrenda> mycolorprendas = new HashMap<Integer,ColorPrenda>();
private ColorPrenda color ;
    public ManagedBeanColorPrenda() {
        lista = new LinkedList<ColorPrenda>();
        color = new ColorPrenda();
    }
public List<ColorPrenda> getLista_colore(){
    try {
        lista = colorPrendaFacade.findAll();
    } catch (Exception e) {
        e.printStackTrace();
    }
    return lista;
}

    public List<SelectItem> getColorprendasItems() {
         lista = new ArrayList<ColorPrenda>();
       colorprendasItems = new LinkedList<SelectItem>();
        lista = colorPrendaFacade.findAll();
        for(ColorPrenda p: lista){
       mycolorprendas.put(p.getIdColorPrenda(), p);
            colorprendasItems.add(new SelectItem(p, p.getNombreColorPrenda()));
        }
        return colorprendasItems;
    }

    public ColorPrenda getColor() {
        return color;
    }

    public void setColor(ColorPrenda color) {
        this.color = color;
    }

    public void setColorprendasItems(List<SelectItem> colorprendasItems) {
        this.colorprendasItems = colorprendasItems;
    }

    public HashMap<Integer, ColorPrenda> getMycolorprendas() {
        return mycolorprendas;
    }

    public void setMycolorprendas(HashMap<Integer, ColorPrenda> mycolorprendas) {
        this.mycolorprendas = mycolorprendas;
    }

   

public ColorPrenda getColorprenda(Integer id) {
           return (ColorPrenda) mycolorprendas.get(id);

    }





public String nuevo_color(){
color = new ColorPrenda();
return "nuevo_color";
}

public String Nueva_Ubicacion2(){
color = new ColorPrenda();
return "nueva_ubicacion2";
}

 public String crear(){
     try {
         colorPrendaFacade.create(color);
     } catch (Exception e) {
    e.printStackTrace();
     }

return "ubicacion2?faces-redirect=true";
 }

 public String Volver_Ubicacion2(){
return "index?faces-redirect=true";
     }

}


